<template>
  <div class="app-container">
  			<el-select v-model="initsort" placeholder="请选择">
			<el-option label="全部" value=""></el-option>
    <el-option label="A" value="A"> </el-option>
     <el-option label="B" value="B"> </el-option>
      <el-option label="C" value="C"> </el-option>
  </el-select>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      style="width:100%"
      fit
      highlight-current-row
    >
      <el-table-column label="序号"  align="center">
        <template slot-scope="scope">
         {{scope.row.number}}
        </template>
      </el-table-column>

      <el-table-column label="姓名"  align="center">
        <template slot-scope="scope">
         {{scope.row.name}}
        </template>
      </el-table-column>

      <el-table-column label="理论知识成绩" align="center">
        <template slot-scope="scope">
          <el-input v-model="scope.row.theorys" placeholder="请输入理论知识成绩"></el-input>
        </template>
      </el-table-column>

    </el-table>
    <el-row style="text-align: right; margin-right: 10px;">
    		<el-button type="primary" style="margin-top: 20px; "  @click="save" >保存</el-button>
    </el-row>



   <el-row style="text-align: right; margin-right: 10px;">
		  	<div class="grid-content bg-purple-light">
			  <el-pagination
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page.sync="pageNum"
	      :page-size="pageSize"
	      layout="total, prev, pager, next"
	      :total="total">
	    </el-pagination>


			  </div>
	</el-row>




  </div>
</template>

<script>
  import {getList,saveTheorys} from '@/api/table'

  export default {
    filters: {
      statusFilter(status) {
        const statusMap = {
          published: 'success',
          draft: 'gray',
          deleted: 'danger'
        }
        return statusMap[status]
      }
    },
    data() {
      return {
        input: null,
        list: null,
        pages:null,//总页数
        total:null,//总条数
        pageNum:1,//当前页
        listLoading: true,
        pageSize:15,
        initsort:null
      }
    },
     watch: {
      initsort(val) {
      this.fetchData()
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        this.listLoading = true
        getList(this.pageNum,this.pageSize,this.initsort).then(response => {
					this.pages=response.data.pages

					this.total=response.data.total
					this.pageNum=response.data.pageNum
          this.list = response.data.list
          this.listLoading = false
        })
      },
      /*保存本页数据*/
     save(){
    	//遍历当前的list集合如果填写的成绩为null 则不执行添加
    	for(var i=0;i<this.list.length;i++){
    		if(this.list[i].theorys===""){
    			//给出提示
    			  this.$message.error('请填写完整信息');
    			return

    		}
    	}
     	saveTheorys(this.list).then(response=>{
     		console.log(response)
     		if(response.code==200){

     			this.$message({
          message: response.msg,
          type: 'success'
        });


     		}else if(response.code==500){
     		 this.$message.error('保存信息失败');

     		}
     	})



     },

      handleCurrentChange(e){
      	this.pageNum=e
      	this.fetchData()
      },
      handleSizeChange(e){
      	console.log("handleSizeChange")
      	console.log(e)
      }
    }
  }
</script>
